from django.db import models
from django.contrib.auth.models import User

class Feed(models.Model):
	title = models.CharField(max_length=200)
	link =  models.URLField(verify_exists=True)
	subtitle = models.CharField(max_length=200, blank=True)
	rights = models.CharField(max_length=200, blank=True)
	updated = models.DateTimeField(null=True)
	author = models.CharField(max_length=200, blank=True)
	publisher = models.CharField(max_length=200, blank=True)
	etag = models.CharField(max_length=40, blank=True)
	active = models.BooleanField(default=True)
	subscriber = models.ManyToManyField(User, through='Subscription', null=True)

class Entry(models.Model):
	feed = models.ForeignKey(Feed)
	title = models.CharField(max_length=200)
	link = models.URLField(verify_exists=True)
	summary = models.TextField(blank=True)
	content = models.TextField(blank=True)
	published = models.DateTimeField()
	updated = models.DateTimeField(null=True)
	author = models.CharField(max_length=200, blank=True)
	publisher = models.CharField(max_length=200, blank=True)
	read = models.ManyToManyField(User, through='EntryRead', null=True)

class Subscription(models.Model):
	feed = models.ForeignKey(Feed)
	user = models.ForeignKey(User)
	name = models.CharField(max_length= 200)

class EntryRead(models.Model):
	entry = models.ForeignKey(Entry)
	user = models.ForeignKey(User)
	read = models.BooleanField(default=True)
	flagged = models.BooleanField(default=False)
